﻿#include "ResizeWidget.h"
#include <QPainter>
#include <QDebug>

ResizeWidget::ResizeWidget(QWidget *parent) : QWidget(parent)
{
    m_image = new QImage("/Users/sl/img.png");
    m_bkg = new QImage(1200,840,QImage::Format_ARGB32);

    resize(600,420);
    //    qDebug() << this->rect();
    //    QPixmap map = grab(QRect(0,0,600,420));
    //    qDebug() << map.size();
    //    grab().save("/Users/sl/hehe.png");

    QPixmap pixmap(this->size());
    this->render(&pixmap);
    pixmap.save("/Users/sl/hehe.png");
}

void ResizeWidget::paintEvent(QPaintEvent *event)
{
    QPainter p(m_bkg);
    p.setRenderHint(QPainter::Antialiasing);
    m_bkg->fill(0);

    p.drawImage(QRect(0,0,m_image->width(),m_image->height()),*m_image);

    QPainter main(this);
    main.setRenderHint(QPainter::Antialiasing);
    main.drawImage(this->rect(),*m_bkg);
}
